package com.tanhua.server.controller;

import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 刘付磊
 * @date 2021/11/11 0011
 */
@RestController
@RequestMapping("/user")
public class Logincontroller {

    @Autowired
    private UserService userService;

    //获取登录验证码
    //获取参数：phone（map）
    //响应：void
    //ResponseEntity设置返回值内容 手动指定状态码
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        String phone = (String) map.get("phone");
        userService.sendMsg(phone);
        //return ResponseEntity.status(500).body("发送成功");
        return ResponseEntity.ok(null);//正常返回状态码200
    }

    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
            //1.调用map集合获取请求的参数
            String phone = (String) map.get("phone");
            String code = (String) map.get("verificationCode");
            //2.调用userservice完成用户登录
            Map retMap = userService.loginVerification(phone,code);
            //3.构造返回
            return ResponseEntity.ok(retMap);
    }
}
